package com.github.livebase.util;

import androidx.annotation.NonNull;
import androidx.core.util.Pools;

/**
 * @ClassName LivePool
 * @description:
 * @author: biao532
 * @create: 2024-01-31 21:47
 * @Version 1.0
 **/
public abstract class LivePool<T> extends Pools.SimplePool<T> {
    /**
     * Creates a new instance.
     *
     * @param maxPoolSize The max pool size.
     * @throws IllegalArgumentException If the max pool size is less than zero.
     */
    public LivePool(int maxPoolSize) {
        super(maxPoolSize);
    }

    @Override
    public T acquire() {
        T r = super.acquire();
        if (r == null) {
            return createNewObject();
        }
        return r;
    }

    @Override
    public boolean release(@NonNull T instance) {
        return super.release(instance);
    }

    protected abstract T createNewObject();
}
